<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>商品浏览规则</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <!--日期选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
    <!--修改图片-->
    <link rel="stylesheet" href="js/dropzone/min/basic.min.css" />
    <link rel="stylesheet" href="js/dropzone/min/dropzone.min.css" />
    <!--时间选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
    <style>
        .table input[type="checkbox"] {
            margin: 0px auto !important;
            width: 20px;
            height: 20px;
        }
    </style>


</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">

                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">确定</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" onclick="selectBtn(1)">全选</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-pink btn_query btn-round" type="button" onclick="selectBtn(0)">全不选</button>
                            </div>
                        </form>
                    </div>

                </div>
                <div class="card-body" >

                    <table id="grid_dataPlus" class="table text-nowrap"></table>

                </div>
            </div>
        </div>
    </div>




    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.message.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>

    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
    <!-- jquery-form表单提交插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
    <!-- bootstrap弹出框插件 -->
    <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
    <!-- 表单填充插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
    <!-- 邮箱自动填充插件 -->
    <script type="text/javascript" src="js/email/autoMail.js"></script>
    <!-- boostrap-combox下拉框检索插件 -->
    <script type="text/javascript" src="js/suggest/bootstrap-suggest.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.suggest.js"></script>
    <!--日期选择插件-->
    <script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    <!-- 调用日期插件 -->
    <script type="text/javascript" src="js/main.min.js"></script>
    <script type="text/javascript" src="js/dropzone/min/dropzone.min.js"></script>
    <script src="js/bootstrap-datetimepicker/moment.min.js"></script>
    <script src="js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="js/bootstrap-datetimepicker/locale/zh-cn.js"></script>
    <script type="text/javascript">


        //设置表头
        var columns = [
            {field: 'ruleId',title: '是否选中',formatter: function (value, row, index) {
                    var html="";
                 if(value=='0'){
                     html="<input name='ruleId'   value='"+JSON.stringify(row)+"'  type='checkbox'/>"
                 }else{
                     html="<input name='ruleId' value='"+JSON.stringify(row)+"' type='checkbox'  checked='checked'/>"
                 }
                   return html;
             }},
            {field: 'productId',title: '商品'},
            {field: 'businessId',title: '店铺id',disable:true},
            {field: 'productName',title: '商品名称'},
            {field: 'mainPicture',title: '商品主图',formatter: function (value, row, index) {
                    if(value!=null&&value!=''){
                       var  html="&nbsp;&nbsp;<img style='width: 60px;height: 60px; border:1px solid #2ba3f6' src='"+value+"'/>";
                        return html;
                    }else {
                        return "无图片"
                    }
            }},

        ];


        var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
        var theRequest = {};
        if ( url.indexOf( "?" ) != -1 ) {
            var str = url.substr( 1 ); //substr()方法返回从参数值开始到结束的字符串；
            var strs = str.split( "&" );
            for ( var i = 0; i < strs.length; i++ ) {
                theRequest[ strs[ i ].split( "=" )[ 0 ] ] = ( strs[ i ].split( "=" )[ 1 ] );
            }

        }

        zero2one.datagrid("grid_dataPlus", "/remote/searchProduct/yzSearch",function (params) {
            return $.extend(zero2one.tableInitParam(params), theRequest);
        }, columns);



        //全选或全不选
        function selectBtn(status){

            var vo={"status" : status};
            var object = $.extend({}, theRequest, vo);
            if(status==1){

                $.messager.confirm("温馨提示", "您确定全选商品吗?", function () {
                    $.ajax({
                        url: '/remote/goodsBrowse/selectAllOrNo',
                        contentType:'application/json',
                        type: 'post',
                        data: JSON.stringify(object),
                        dataType: 'json',
                        success: function (res) {
                            if (res.success){
                                $.messager.alert("温馨提示", "操作成功,2S之后刷新");
                                setTimeout(function () {
                                    window.location.href= "/goodsBrowse.html";
                                }, 2000);
                            }else {
                                $.messager.alert("温馨提示","操作失败");
                            }
                        }
                    });

                })

            }else {
                $.messager.confirm("温馨提示", "您确定取消全部商品吗?", function () {

                    $.ajax({
                        url: '/remote/goodsBrowse/selectAllOrNo',
                        contentType:'application/json',
                        type: 'post',
                        data: JSON.stringify(object),
                        dataType: 'json',
                        success: function (res) {
                            if (res.success){
                                $.messager.alert("温馨提示", "操作成功,2S之后刷新");
                                setTimeout(function () {
                                    window.location.href= "/goodsBrowse.html";
                                }, 2000);
                            }else {
                                $.messager.alert("温馨提示","操作失败");
                            }
                        }
                    });

                })

            }

        }



        //选择单独商品
        $("#searchFormBtn").click(function () {

            var chk_value =[];
            $('input[name="ruleId"]:checked').each(function(){
                chk_value.push(eval('(' + $(this).val() + ')'));
            });
            var ruleIdplus=theRequest.ruleId;
            var busId=theRequest.businessId;

            var object ={'choose':chk_value,"ruleIdplus":ruleIdplus,"busId":busId};

                if(chk_value.length>0){
                    $.messager.confirm("温馨提示", "您确定勾选的商品吗?", function () {

                    $.ajax({
                        url: '/remote/goodsBrowse/buttonRule',
                        contentType:'application/json',
                        type: 'post',
                        data: JSON.stringify(object),
                        dataType: 'json',
                        success: function (res) {
                            if (res.success){
                                $.messager.alert("温馨提示", "操作成功,2S之后刷新");
                                setTimeout(function () {
                                    window.location.href= "/goodsBrowse.html";
                                }, 2000);
                            }else {
                                $.messager.alert("温馨提示","操作失败");
                            }
                        }
                    });

                })
                }else {
                    $.messager.alert("请选中要操作商品");
                }
        })


    </script>
</div>
</body>
</html>
